# Maintainer: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
# Contributor: Jan de Groot <jan@archlinux.org>

pkgbase=gnome-desktop
pkgname=(
  gnome-desktop-common
  gnome-desktop
  gnome-desktop-4
)
pkgver=44.0
pkgrel=1
epoch=1
pkgdesc="Library with common API for various GNOME modules"
url="https://gitlab.gnome.org/GNOME/gnome-desktop"
arch=(loong64 x86_64)
license=(
  GPL
  LGPL
)
makedepends=(
  bubblewrap
  git
  gobject-introspection
  gsettings-desktop-schemas
  gtk-doc
  gtk3
  gtk4
  iso-codes
  libseccomp
  libxkbcommon
  meson
  systemd
  xkeyboard-config
  yelp-tools
)
checkdepends=(xorg-server-xvfb)
_commit=97c0344b3ba955bb6f6fe74ca03cc399a81acaa5  # tags/44.0^0
source=("git+https://gitlab.gnome.org/GNOME/gnome-desktop.git#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd $pkgbase
  git describe --tags | sed 's/[^-]*-g/r&/;s/-/+/g'
}

prepare() {
  cd $pkgbase
}

build() {
  local meson_options=(
    -D debug_tools=false
    -D gtk_doc=true
  )

  arch-meson $pkgbase build "${meson_options[@]}"
  meson compile -C build
}

check() {
  dbus-run-session xvfb-run -s '-nolisten local' \
    meson test -C build --print-errorlogs
}

_pick() {
  local p="$1" f d; shift
  for f; do
    d="$srcdir/$p/${f#$pkgdir/}"
    mkdir -p "$(dirname "$d")"
    mv "$f" "$d"
    rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
  done
}

package_gnome-desktop-common() {
  pkgdesc+=" (common files)"
  depends=(
    bubblewrap
    gsettings-desktop-schemas
    iso-codes
    libseccomp
    libxkbcommon
    systemd
    xkeyboard-config
  )

  meson install -C build --destdir "$pkgdir"

  cd "$pkgdir"

  _pick gtk3 usr/include/gnome-desktop-3.0
  _pick gtk3 usr/lib/libgnome-desktop-3.so*
  _pick gtk3 usr/lib/pkgconfig/gnome-desktop-3.0.pc
  _pick gtk3 usr/lib/girepository-1.0/GnomeDesktop-3.0.typelib
  _pick gtk3 usr/share/gir-1.0/GnomeDesktop-3.0.gir

  _pick gtk4 usr/include/gnome-desktop-4.0
  _pick gtk4 usr/lib/libgnome-*-4.so*
  _pick gtk4 usr/lib/pkgconfig/gnome-*-4.pc
  _pick gtk4 usr/lib/girepository-1.0/Gnome*-4.0.typelib
  _pick gtk4 usr/share/gir-1.0/Gnome*-4.0.gir
}

package_gnome-desktop() {
  pkgdesc+=" (GTK3)"
  depends=(
    gnome-desktop-common="$epoch:$pkgver-$pkgrel"
    gtk3
  )
  provides=(libgnome-desktop-3.so)

  mv gtk3/* "$pkgdir"
}

package_gnome-desktop-4() {
  pkgdesc+=" (GTK4)"
  depends=(
    gnome-desktop-common="$epoch:$pkgver-$pkgrel"
    gtk4
  )
  provides=(libgnome-{bg,desktop,rr}-4.so)

  mv gtk4/* "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
